

<template>
  <div class="body-content">
    <!-- 第一行 -->
    <div>
      <div class="title">
        图像生成
      </div>
      <div class="line">
        <el-steps :active="5" align-center>
        <el-step title="特征绘制"/>
        <el-step title="参数设置"/>
        <el-step title="草图生成"/>
        <el-step title="风格迁移"/>
        <el-step title="图像筛选"/>
      </el-steps>
      </div>
    </div>
    <!-- 第二行 -->
    <div>
      <el-row style="flex">
        <div class="first-box">
        <div class="box-title">
          1.特征绘制
        </div>
        <div class="box-first">
          <el-upload
            class="avatar-uploader"
            action="/api/tab0/D5resized-upload-file"
            :show-file-list="false"
            :on-success="handleAvatarSuccess"
            :before-upload="beforeAvatarUpload"
          >
            <img v-if="imageUrl" :src="imageUrl" class="avatar" />
            <el-icon v-else class="avatar-uploader-icon">上传图片</el-icon>
          </el-upload>

        </div>
        <div class="box-title">
          重要特征选择
        </div>
       </div>
       <!-- 第二个 -->
      <div class="second-box">
        <div class="box-title">
          2. 草图生成参数设置
        </div>
        <div class="laber">
          <div class="input-container">
            <label >X  轴范围</label>
            <div class="input-box">
              <input type="text" class="input-field" placeholder="[0,1]">
            </div>
          </div>
          <div class="input-container">
            <label >Y  轴范围</label>
            <div class="input-box">
              <input type="text"  class="input-field" placeholder="[0,1]">
            </div>
          </div>
          <div class="input-container">
            <label >X  轴缩放</label>
            <div class="input-box">
              <input type="text"  class="input-field" placeholder="[0,1]">
            </div>
          </div>
          <div class="input-container">
            <label >Y  轴缩放</label>
            <div class="input-box">
              <input type="text"  class="input-field" placeholder="[0,1]">
            </div>
          </div>
          <div class="input-container">
            <label >旋转角度</label>
            <div class="input-box">
              <input type="text"  class="input-field2" placeholder="0">
              ~<input type="text"  class="input-field3" placeholder="180">
            </div>
          </div>
          <div class="input-container">
            <label >生成张数</label>
            <div class="input-box">
              <input type="text"  class="input-field" placeholder="200">
            </div>
          </div>
        </div>
      </div>

        <!-- 第三行 -->
        <div class="third-box">
          <div class="box-title">
            3.草图生成
          </div>
          <div class="begin" @click="tab0MainSubmit">开始生成</div>
          <div class="box-blue22">
            <div class="demo-image__lazy">
              <el-image v-for="url in imageUrlList" :key="url" :src="url" lazy />
            </div>
          </div>
          <div class="box-title">
            生成草图展示
          </div>
       </div>
      </el-row>
    </div>
    <!-- 第三行 -->
    <div>
      <el-row style="flex">
        <div class="third-box">
          <div class="box-title">
            4. 风格迁移
          </div>
          <div class="generation-options">
          <span>生成模型选择：</span>
          <select class="model-select">
            <option value="cyclegan" selected>cyclegan</option>
           
          </select>
          <div class="begin" @click="tab0MainSubmit2">开始生成</div>
        </div>
          
        <div class="box-blue22">
            <div class="demo-image__lazy">
              <el-image v-for="url in imageUrlList2" :key="url" :src="url" lazy />
            </div>
          </div>
          <div class="box-title">
            生成图像展示
          </div>
       </div>

        <!-- 第五个 -->
        <div class="third-box">
        <div class="box-title">
          5. 图像筛选
        </div>
        <div class="detailed-content">
          <!-- 左侧部分，占据2/5 -->
          <div class="left-content">
            <div>
              <div class="box-blue" style="margin-top: 40px;"> 
              <img class="inner-button2" :src="selectedImageUrl" />
              <!-- <img class="inner-button2" :src="selectedImageUrl" /> -->
            </div>
        <div class="box-title" style="margin-top: 40px;" >
          生成图像
        </div>
            </div>
            
          </div>
          <!-- 右侧部分，占据3/5 -->
          <div class="right-content">
            <!-- 第一行，水平居中显示的图像生成记录 -->
            <div class="box-title">
              图像生成记录
            </div>
            <!-- 表格 -->
            <el-table
          :data="imageUrlTable"
          style="width: 100%; max-height: 300px; overflow: auto;margin-bottom: 10px;"
          stripe
          border
          @row-click="handleRowClick"
        >
          <el-table-column prop="index" label="序号" />
          <el-table-column prop="imageName" label="图片名" />
          <el-table-column prop="time" label="生成时间" />
          <el-table-column label="操作">
            <template #default="{ row }">
              <el-button type="danger" @click="handleDelete(row)">删除图像</el-button>
            </template>
          </el-table-column>
          <!-- <el-table-column label="操作">
            <template #default="{ row }">
              <el-button type="danger" @click="handleDelete(row)">删除图像</el-button>
            </template>
          </el-table-column> -->
          </el-table>
            <!-- 按钮 -->
            <!-- <div class="action-buttons">
              <div class="delete-button">删除图像</div>
              <div class="addToDatabase-button">加入数据库</div>
            </div> -->
          </div>
        </div>
      </div>
      </el-row>
    </div>
  </div>
</template>
<script setup>
import { getTab0List, getTab0Submit,getTab1Submit,getTab1List } from "@/api/index.js"
import { ref } from 'vue'

const imageUrl = ref('')
const imageUrlList = ref('')
const imageUrlList2 = ref('')
const imageUrlTable = ref('')
const selectedImageUrl = ref('') // 用于存储选中的图像URL

const handleRowClick = (row) => {
  selectedImageUrl.value = row.imageUrl
}

const handleDelete = (row) => {
  const index = imageUrlTable.value.findIndex(item => item.imageUrl === row.imageUrl)
  if (index !== -1) {
    imageUrlTable.value.splice(index, 1)
  }
}

// // 点击列表时更新selectedImageUrl
// const handleImageClick = (url) => {
//   selectedImageUrl.value = url
// }

const handleAvatarSuccess = (response) => {
  // /tab0/D5resized-download/{filename}
  imageUrl.value = '/api/tab0/D5resized-download/' + response.filename
}

  const tab0MainSubmit = () => {
    console.log("tab0MainSubmit")
    getTab0Submit().then(() => {
        getTab0List().then((res) => {
          console.log("getTab0List",res)
          const modifiedUrls = res.map(item => 'http://127.0.0.1:5000/tab0/Dresult_L/download/' + item.imageName)
          imageUrlList.value = modifiedUrls
          console.log("imageUrlList",imageUrlList.value)
        })
      })
  }
  const tab0MainSubmit2 = () => {
    console.log("tab0MainSubmit")
    getTab1Submit().then(() => {
      getTab1List().then((res) => {
          console.log("getTab0List",res)
          //url
          const modifiedUrls = res.map(item => 'http://127.0.0.1:5000/tab1/test_latestDownload/' + item.imageName)
          imageUrlList2.value = modifiedUrls
          //table
          const modifiedData = res.map((item, index) => {
          return {
            index: index + 1,
            imageName:item.imageName,
            imageUrl: 'http://127.0.0.1:5000/tab1/test_latestDownload/' + item.imageName,
            time: item.time
           }
          })
          imageUrlTable.value = modifiedData
          console.log("imageUrlTable",imageUrlTable.value)
          console.log("imageUrlList2",imageUrlList2.value)
        })
      })

  }
</script>
<style scoped>
.body-content{
  /* max-height: calc(100vh - 90px); */
}
.title{
  font-size: 19px;
  font-weight: 400;
  margin:10px
}
.line{
  margin-bottom: 1px;
}
::v-deep .el-step__head.is-finish {
    color: #1a1b1d;
    border-color: #2a2c2f;
}
::v-deep .el-step__title.is-finish {
  color: #1a1b1d;
}
.box-title{
  font-size: 16px;
  font-weight: 600;
  margin:10px;
  text-align:center
}
.first-box{
  border: gray solid 1px;
  /* min-width: 300px; */
  margin:15px; 
}
.box-blue {
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #80578379;
  width: 200px;
  height: 200px;
  margin: 10px 40px;
}
.box-first {
  border: #8c939d solid 1px;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 200px;
  height: 200px;
  margin: 10px 40px;
}
.box-blue22 {
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #80578379;
  width: 400px;
  height: 200px;
  margin: 10px 40px;
}
.box-blue2 {
  display: flex;
  justify-content: center;
  align-items: center;
  /* background-color: #5b9bd5; */
  width: 400px;
  height: 200px;
  margin: 10px 40px;
}


.inner-button {
  width: 60px;
  height: 30px;
  background-color: aliceblue;
  display: flex;
  justify-content: center;
  align-items: center;
}
.inner-button2{
  color: white;
  font-size: 30px;
}
.second-box{
  margin:15px; 
  border: gray solid 1px;
  /* min-width: 300px; */
}
.input-container {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}

.label {
  margin-right: 10px; 
}

.input-box {
  justify-content: center;
  align-items: center;
  display: flex;
  align-items: center;
  margin-left: 40px;
}

.input-field {
  width: 100px; /* 根据需要调整宽度 */
  padding: 5px;
  height: 25px;
  box-sizing: border-box;
  text-align: center;
}
.input-field2 {
  width: 40px; /* 根据需要调整宽度 */
  padding: 5px;
  height: 25px;
  box-sizing: border-box;
  text-align: center;
  margin-right:5px
}
  .input-field3 {
  width: 50px; /* 根据需要调整宽度 */
  padding: 5px;
  height: 25px;
  box-sizing: border-box;
  text-align: center;
  margin-left: 5px;
  }
.laber{
  margin-left: 35px;
}
.third-box{
  margin:10px; 
  border: gray solid 1px;
  /* min-width: 600px; */
  display: flex;
  flex-direction: column;
  align-items: center;
}
.begin{
  border: black solid 1px;;
  width: 80px;
  height: 30px;
  background-color: aliceblue;
  display: flex;
  justify-content: center;
  text-align:center;
  left: 50%;
  
}

.row-container {
  display: flex;
  justify-content: space-between;
  margin: 0 -10px; /* 调整整体的 margin */
}

.first-box,
.second-box,
.third-box {
  flex: 1;
  margin:  10px; /* 调整每个盒子的 margin */
  display: flex;
  flex-direction: column;
  align-items: center;
}
.generation-options {
  display: flex;
  align-items: center;
}

.model-select {
  margin-right: 10px; /* 调整下拉框与按钮之间的间距 */
}

/* .begin {
  border: 1px solid black;
  padding: 5px 10px;
  cursor: pointer;
  background-color: aliceblue;
} */
.third-box {
  margin: 15px;
  border: gray solid 1px;
  min-width: 600px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.detailed-content {
  display: flex;
  width: 100%;
}

.left-content {
  width: 35%; 
  display: flex;
  justify-content: center;
  align-items: center;/* 占据2/5 */
}

.right-content {
  width: 65%; /* 占据3/5 */
}



.image-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 10px;
}

th, td {
  border: 1px solid white;
  text-align: center;
  padding: 8px;
}

.deep-blue-row {
  background-color: #5b9bd5;
  color: white;
  height: 30px; 
}
.blue-row {
  background-color: #d2deef;
  color: white;
  height: 30px; 
}

.white-row {
  background-color: white;
  height: 30px; 
}

.action-buttons {
  display: flex;
  justify-content: right;
}

.delete-button,
.addToDatabase-button {
  border: 1px solid black;
  padding: 5px 10px;
  cursor: pointer;
  background-color: aliceblue;
  margin:10px;
}
.avatar-uploader .el-upload {
  border: 1px dashed var(--el-border-color);
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  /* transition: var(--el-transition-duration-fast); */
}

.avatar-uploader .el-upload:hover {
  border-color: var(--el-color-primary);
}
.avatar{
  width: 200px;
  height: 200px;
}

.el-icon.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  text-align: center;
}
.demo-image__lazy {
  height: 200px;
  width: 400px;
  overflow-y: auto;
}
.demo-image__lazy .el-image {
  display: block;
  min-height: 200px;
  margin-bottom: 10px;
}
.demo-image__lazy .el-image:last-child {
  margin-bottom: 0;
}

</style>
